import * as http from '@/utils/request'

const USER_BASE_URL = '/user'

/** 用户登录注册相关请求 */
export const UserApi = {
  login: (data: UserDto) => {
    return http.postForItem<BlogUserLoginVo>(`/login`, data)
  },

  logout: () => {
    return http.postForBase(`/logout`)
  },

  register: (data: UserDto) => {
    return http.postForBase(`${USER_BASE_URL}/register`, data)
  },

  toGetUserInfo: () => {
    return http.getItem<UserInfoVo>(`${USER_BASE_URL}/userInfo`)
  },
  toUpdateUserInfo: (data: UserDto) => {
    return http.putForBase(`${USER_BASE_URL}/userInfo`, data)
  },
}

export interface UserDto {
  serialVersionUID?: number

  id?: number

  userName?: string

  nickName?: string

  password?: string

  type?: string

  status?: string

  email?: string

  phonenumber?: string

  sex?: string

  avatar?: string

  delFlag?: number

  createBy?: number

  createTime?: any

  updateBy?: number

  updateTime?: any
}

export interface UserInfoVo {
  /**
   * 主键
   */
  id?: number

  /**
   * 昵称
   */
  nickName?: string

  /**
   * 头像
   */
  avatar?: string

  sex?: string

  email?: string
}

export interface BlogUserLoginVo {
  token?: string

  userInfo?: UserInfoVo
}
